package com.blacktry.config.schedule;

import com.blacktry.service.JobService;
import org.quartz.SchedulerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.ServletContextAware;

import javax.servlet.ServletContext;

@Configuration
public class ScheduleJobInitConfig implements ServletContextAware {
    private static final Logger logger = LoggerFactory.getLogger(ScheduleJobInitConfig.class);
    @Autowired
    private JobService jobService;
    @Override
    public void setServletContext(ServletContext servletContext) {
        try {
            //启动数据库中配置的定时任务
            jobService.initScheduleJob();
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
        logger.info("初始化定时任务成功 ...");
    }
}